%%%-------------------------------------------------------------------
%%% @author Rain
%%% @doc 时间相关接口
%%% @end
%%%-------------------------------------------------------------------
-module(game_util_time).
-author("Rain").

-export([now_ms/0, now_sec/0]).
-export([date_time_str/0, date_time_str/1]).
-export([date_str/0, date_str/1]).

%% @doc 当前时间（秒）
now_sec() ->
    {MegaSecs,Secs, _MicroSecs} = os:timestamp(),
    MegaSecs * 1000000 + Secs.

%% @doc 当前时间（毫秒）
now_ms() ->
    {MegaSecs,Secs, MicroSecs} = os:timestamp(),
    MegaSecs * 1000000000 + Secs * 1000 + MicroSecs div 1000.

%% @doc 日期时间字符串
date_time_str() ->
    date_time_str("").

%% @doc 日期时间字符串
date_time_str(ConnectStr) ->
    {{Y, M, D}, {H, Min, S}} = calendar:now_to_datetime(os:timestamp()),
    lists:flatten(io_lib:format("~w~s~2..0B~s~2..0B~s~2..0B~s~2..0B~s~2..0B", [Y, ConnectStr, M,
        ConnectStr, D, ConnectStr, H, ConnectStr, Min, ConnectStr, S])).


%% @doc 日期字符串
date_str() ->
    date_str("").

%% @doc 日期时间字符串
date_str(ConnectStr) ->
    {{Y, M, D}, _} = calendar:now_to_datetime(os:timestamp()),
    lists:flatten(io_lib:format("~w~s~2..0B~s~2..0B", [Y, ConnectStr, M, ConnectStr, D])).

